<?php

namespace Apps\AppApi\Method\BeautyCanon;

use Apps\Common\Models\CosBeautyCanon;
use Apps\Common\Libs\PicUrl;
use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;

/*
 * 美粒宝典详情
 */
class GetInfo extends BaseMethod {
	
	
	private $bcanonInfo = [];
	
	public function run() {
		
		$id = intval($this->getDataItem('id',0));
		
		if(0 < $id) {
			$this->bcanonInfo = CosBeautyCanon::query()
				-> columns([
					'content',
				    'title',
				    'settime',
					'fit'
					])		         
		        ->where('state != 3 and id = '.$id)
		        ->execute()->getFirst();
		        } else {
		            return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '参数异常');
		        }
		
		        if($this->bcanonInfo) {
		        	if($this -> bcanonInfo -> fit == null){
		        		$this -> bcanonInfo -> fit = 0;
		        	}
		        	//浏览量加1
		        	$query = new CosBeautyCanon();
		        	$model = $query->findFirst(' id = '.$id);
		        	//modify by jinyu 2016/01/04 阅读量随机增加，随机区间config配置
		        	$min = $this->getConfig()->min;
		        	$max = $this->getConfig()->max;
		        	$num = mt_rand($min,$max);
		        	$model -> fit = $this -> bcanonInfo -> fit + $num;
		        	$model -> save();	
		        	//循环处理内容中的图片
		        	$this -> bcanonInfo -> content = str_replace('src="/ueditor/php/upload/image/','src="http://meelier.com/ueditor/php/upload/image/', $this -> bcanonInfo -> content);
		            
		        } else {
		            $this->bcanonInfo = null;
		        }
		        $this->setResult($this->bcanonInfo);
		
				
		
	}
}
